package net.dgg.rz.production.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import net.dgg.framework.tac.utils.idutil.DggKeyWorker;
import net.dgg.iboss.base.entity.uc.CustomerDTO;
import net.dgg.iboss.base.service.CmsService;
import net.dgg.iboss.base.service.UcApiService;
import net.dgg.iboss.base.util.CustomerNumberEncryptionUtil;
import net.dgg.iboss.base.util.DateUtil;
import net.dgg.iboss.base.util.DesUtil;
import net.dgg.rz.api.production.service.ApiProductionService;
import net.dgg.rz.common.base.service.BaseService;
import net.dgg.rz.common.constant.ModuleCodeConstant;
import net.dgg.rz.common.constant.ScNoteType;
import net.dgg.rz.common.constant.ScProductConstant;
import net.dgg.rz.common.dao.ProductDao;
import net.dgg.rz.common.entity.CustomerRecord;
import net.dgg.rz.common.excption.CommonExcption;
import net.dgg.rz.common.service.CommonMangerExtService;
import net.dgg.rz.common.service.CommonService;
import net.dgg.rz.common.service.ZzWorkDayService;
import net.dgg.rz.common.systemRecord.entity.SystemRecord;
import net.dgg.rz.common.systemRecord.service.SystemRecordService;
import net.dgg.rz.common.utils.*;
import net.dgg.rz.production.dao.*;
import net.dgg.rz.production.entity.*;
import net.dgg.rz.production.entity.dto.OrderCountDto;
import net.dgg.rz.production.entity.dto.ProductOrderDto;
import net.dgg.rz.production.entity.dto.UploadWjOrderDto;
import net.dgg.rz.production.exception.ProductOrderExcption;
import net.dgg.tmd.foundation.platform.common.util.TranslateUtil;
import net.dgg.tmd.foundation.platform.datapermission.entity.DataAuthDTO;
import net.dgg.tmd.foundation.platform.datapermission.service.DataPermissionAssocService;
import net.dgg.tmd.foundation.platform.org.entity.OrganizationEntity;
import net.dgg.tmd.foundation.platform.org.service.OrganizationManager;
import net.dgg.tmd.foundation.platform.session.SessionManager;
import net.dgg.tmd.foundation.platform.user.entity.UserEntity;
import net.dgg.tmd.foundation.platform.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.ParseException;
import java.util.*;

/**
 * Created by cuipeng on 2018/12/19.
 */
@Service
public class AllOrderService extends BaseService {

    @Autowired
    private DataPermissionUtils dataPermissionUtils;

    @Autowired
    private DataPermissionAssocService dataPermissionAssocService;

    @Autowired
    private DesUtil desUtil;

    @Autowired
    private ProductOrderDao productOrderDao;

    @Autowired
    private SearchUtils searchUtils;

    @Autowired
    private SessionManager sessionManager;

    @Autowired
    private SystemRecordService systemRecordService;

    @Autowired
    private CmsService cmsService;

    @Autowired
    private UserService userService;

    @Autowired
    private CommonService commonService;

    @Autowired
    private UcApiService ucApiService;

    @Autowired
    private TranslateUtil translateUtil;

    @Autowired
    private ProductTimeStatusDao productTimeStatusDao;

    @Autowired
    private ProductNodeFlowDao productNodeFlowDao;

    @Autowired
    private CommonMangerExtService commonMangerExtService;

    @Autowired
    private ProductNodeDao productNodeDao;

    @Autowired
    private ProductNodeOperatingDao productNodeOperatingDao;

    @Autowired
    private ZzWorkDayService zzWorkDayService;

    @Autowired
    private ProductDao productDao;

    @Autowired
    private CmsService cmsservice;

    @Autowired
    private AssistantDao assistantDao;

    @Autowired
    private OrganizationManager organizationManager;

    @Autowired
    private ProductTimeStatusService productTimeStatusService;

    @Autowired
    private ApiProductionService apiProductionService;
    /**
     * 查询所有生产订单列表
     *
     * @param param
     * @return
     */
    public List<ProductOrderDto> allScOrderWithPage(Map param) {

//        if(null!=param.get("customerPhone")){
//            param.put("customerPhone",desUtil.encrypt(param.get("customerPhone").toString()));
//        }
        if (null == param.get("orderColumn")) {
            param.put("orderDir", "desc");
            param.put("orderColumn", "z.order_time_status,z.node_time_status,z.receive_time_status,z.distribution_time_out_status,t.update_time");
        }
        searchUtils.paramsOperate(param);

        return productOrderDao.scOrderWithPage(param);
    }

    /**
     * 根据生产订单ID查询生产订单信息
     *
     * @param id
     */
    public ProductOrder getProductById(Long id) {
        ProductOrder productOrder = productOrderDao.selectByPrimaryKey(id);
        //翻译字段
        String[] transColum = {"originCode", "status", "suspendReason"};
        productOrder = translateUtil.translateObject(transColum, productOrder);
        //隐藏字段
        String[] hideColum = {"customerPhone"};
        productOrder.setCustomerPhone(desUtil.decrypt(productOrder.getCustomerPhone()));
        productOrder = CustomerNumberEncryptionUtil.encryptionObject(hideColum, productOrder);
        return productOrder;
    }

    /**
     * 退单/废单恢复办理
     *
     * @param ids
     */
    @Transactional
    public void restoreOrder(String ids, String status,String userLoginName) {
        UserEntity userEntity = searchUtils.getcurrUser(new HashMap(){{
            put("userLoginName", userLoginName);
        }});
        ValidateUtils.strNotEmpty(userEntity, ProductOrderExcption.class, "未获取到登陆人，请重新登录！");
        OrganizationEntity operatedOrgan = organizationManager.findOrgEntityByOrgId(userEntity.getOrgId());
        ValidateUtils.strNotEmpty(operatedOrgan, ProductOrderExcption.class, "未获取到登陆人部门信息，请重新登录！");
        ValidateUtils.strNotEmpty(ids, ProductOrderExcption.class, "生产订单ID不能为空！");
        ValidateUtils.strNotEmpty(status, ProductOrderExcption.class, "状态不能为空！");
        if (!status.equals(ScProductConstant.RZSCORDER_STATUS06) && !status.equals(ScProductConstant.RZSCORDER_STATUS10) && !status.equals(ScProductConstant.RZSCORDER_STATUS09)) {
            ValidateUtils.isTrue(false, ProductOrderExcption.class, "状态传入错误，只有废单驳回/退单驳回/已退单这三种状态可以恢复办理！");
        }
        /* 分割字符串*/
        String[] idsStrArray = ids.split(",");
        List<SystemRecord> systemRecords = new ArrayList<>();
        //List<ProductOrder> rzProductOrderList = new ArrayList<>();
        Date now = new Date();
        for (int i = 0; i < idsStrArray.length; i++) {
            String id = idsStrArray[i];
            ProductOrder rzProductOrder = productOrderDao.selectByPrimaryKey(Long.parseLong(id));
            //判断登录人是否有权限操作这条记录
            ValidateUtils.strNotEmpty(rzProductOrder, ProductOrderExcption.class, "未查询到该生产订单的信息");
//            Assert.isTrue(userEntity.getId().equals(rzProductOrder.getFlowUserId()), "您不是这条生产单的流程人员，没有操作这条生产单的权限!");
            ValidateUtils.isTrue(userEntity.getId().equals(rzProductOrder.getFlowUserId()), ProductOrderExcption.class, "您不是这条生产单的流程人员，没有操作这条生产单的权限!");
            //判断订单状态是否可进行操作
            String libStatus = rzProductOrder.getStatus();
            if (!status.equals(libStatus)) {
//                Assert.isTrue(false, "当前订单已更改，请刷新页面重试!");
                ValidateUtils.isTrue(false, ProductOrderExcption.class, "当前订单已更改，请刷新页面重试!");

            }
            /*if (null != rzProductOrder.getBeforeStatus() && !"".equals(rzProductOrder.getBeforeStatus())) {
                rzProductOrder.setStatus(rzProductOrder.getBeforeStatus()); //恢复到退单前的状态
            } else {*/
            rzProductOrder.setStatus(ScProductConstant.RZSCORDER_STATUS02); //办理中
            //}
            this.updateOpt(rzProductOrder, userEntity);
            if (status.equals(ScProductConstant.RZSCORDER_STATUS09) || status.equals(ScProductConstant.RZSCORDER_STATUS06)) {//退单驳回/已退单
                productOrderDao.updateByPrimaryKeySelective(rzProductOrder);
            }
            if (status.equals(ScProductConstant.RZSCORDER_STATUS10)) {
                //判断这条但是是不是待分配的(判断流程人员是不是为空)
                if (StringUtils.isEmpty(rzProductOrder.getFlowUserId())) {//待分配 被废单
                    rzProductOrder.setStatus(ScProductConstant.RZSCORDER_STATUS14);
                    productOrderDao.updateByPrimaryKeySelective(rzProductOrder);
                } else if (StringUtils.isEmpty(rzProductOrder.getReceiveTime())) {
                    //receiveOrderDate接单时间为空 说明是从待接收处废单的   需要跟新节点信息等
                    //rzProductOrder.setReceiveOrderDate(new Date());//添加接单时间
                    //rzProductOrder.setOrderTime(new Date());//添加签单时间
                    //productOrderDao.updateByPrimaryKeySelective(rzProductOrder);
                    singleHandlScrap(rzProductOrder, userEntity);
                } else {
                    productOrderDao.updateByPrimaryKeySelective(rzProductOrder);
                }

            }

            //-------操作记录------------
            SystemRecord systemRecord = new SystemRecord();
            //systemRecord.setId(DggKeyWorker.nextId());
            systemRecord.setWorkId(rzProductOrder.getId());
            systemRecord.setWorkNo(rzProductOrder.getScProductOrderNo());
            systemRecord.setWorkTableName("rzsc_product_order");
            systemRecord.setSource("2");//来源生产
            if (status.equals(ScProductConstant.RZSCORDER_STATUS09) || status.equals(ScProductConstant.RZSCORDER_STATUS06)) {
                systemRecord.setOperateType("26");//操作类型 : 退单恢复办理
                systemRecord.setRemarks(userEntity.getRealName() + userEntity.getLoginName() + "恢复该订单办理");
            } else if (status.equals(ScProductConstant.RZSCORDER_STATUS10)) {
                systemRecord.setOperateType("42");//操作类型 : 废单恢复办理
                systemRecord.setRemarks(userEntity.getRealName() + userEntity.getLoginName() + "恢复该订单办理");
            }
            systemRecord.setId(DggKeyWorker.nextId());
            systemRecord.setOperaterId(userEntity.getId());
            systemRecord.setOperaterName(userEntity.getRealName() + userEntity.getLoginName());
            systemRecord.setOperaterOrgId(operatedOrgan.getId());
            systemRecord.setOperaterOrgName(operatedOrgan.getName());

            systemRecord.setOperateTime(now);
            systemRecords.add(systemRecord);
            //systemRecordService.save(systemRecord);

            //-----------操作记录------------------
            //通过MQ推送消息到UC
            CustomerRecord customerRecord = new CustomerRecord();
            customerRecord.setCustomerId(rzProductOrder.getCustomerId());
            customerRecord.setTableName("rzsc_product_order");
            customerRecord.setTableId(rzProductOrder.getId());
            customerRecord.setTableNo(rzProductOrder.getScProductOrderNo());
            customerRecord.setRemarkType(ScNoteType.RZSC_NOTE_CODE14);
            customerRecord.setCreaterId(userEntity.getId());
            customerRecord.setContent("退/废单恢复办理");
            MQMessageSendUtil.ucMessageSend(customerRecord);
            //同步生产单状态给企大宝
            MQMessageSendUtil.qdsMessageSend(rzProductOrder,null,userEntity);
        }
        systemRecordService.saveRecords(systemRecords); //循环更新记录日志

    }

    @SuppressWarnings("all")
    public void singleHandlScrap(ProductOrder productOrder, UserEntity userEntity) {
        Map map = this.commonMangerExtService.findOrg(userEntity.getOrgId());
     /*   if (null == map) {
           Assert.isTrue(false, "接收失败,系统参数异常,请联系管理员！");
            ValidateUtils.isTrue(false,ProductOrderExcption.class, "接收失败,系统参数异常,请联系管理员！");
        }*/
        ValidateUtils.strNotEmpty(map, ProductOrderExcption.class, "接收失败,系统参数异常,请联系管理员！");
   /*     if(StringUtils.isEmpty(productOrder.getNodeFlowId())) {
            Assert.isTrue(false, "未查询到"+productOrder.getProductOrgName()+"流程节点配置信息");
        }*/
        ValidateUtils.strNotEmpty(productOrder.getNodeFlowId(), ProductOrderExcption.class, "未查询到" + productOrder.getProductOrgName() + "流程节点配置信息");
        Map params = new HashMap();
        params.put("flowId",productOrder.getNodeFlowId());
        params.put("version",productOrder.getVersion());
        List<ProductNode> productNode = productNodeDao.queryByFlowIdAndVersion(params);
        if(null==productNode || productNode.size()==0) {
//            Assert.isTrue(false, "未查询到"+productOrder.getProductOrgName()+"流程节点配置信息");
            ValidateUtils.isTrue(false, ProductOrderExcption.class, "未查询到" + productOrder.getProductOrgName() + "流程节点配置信息");
        }
        Date newDate = new Date();
        productOrder.setReceiverId(userEntity.getId());// 接收人
        productOrder.setReceiverName(userEntity.getRealName() + userEntity.getLoginName());// 接收人
        productOrder.setReceiverOrgId(userEntity.getOrgId());// 接收人部门
        productOrder.setReceiverOrgName(map.get("name").toString());// 接收人部门名称
        productOrder.setReceiveTime(newDate);// 接收时间
        productOrder.setReceiveOrderDate(newDate);//接单时间
        productOrder.setFlowUserId(userEntity.getId());// 流程人员Id
        productOrder.setReceiveTime(newDate);//流程人员接单时间
        productOrder.setFlowUserName(userEntity.getRealName() + userEntity.getLoginName());// 流程人员Id
        productOrder.setFlowUserOrgId(userEntity.getOrgId());// 流程人员Id
        productOrder.setFlowUserOrgName(map.get("name").toString());// 流程人员Id
        productOrder.setUpdaterUser(userEntity);
        productOrder.setUpdaterOrgName(map.get("name").toString());
        productOrder.setUpdateTime(newDate);
        Long operatingId = DggKeyWorker.nextId();//更新记录id
        productOrder.setLatestEndUserId(userEntity.getId());
        productOrder.setLatestEndUserName(userEntity.getRealName() + userEntity.getLoginName());
        productOrder.setLatestEndNodeId(productNode.get(0).getId());
        productOrder.setLatestEndNodeName(productNode.get(0).getName());
        productOrder.setLatestEndNodeTime(newDate);
        productOrder.setLatestNodeOperatingId(operatingId);
        productOrder.setLatestFlowOperatingId(productOrder.getNodeFlowId());
        productOrder.setLatestEndUserOrgId(userEntity.getOrgId());
        productOrder.setStatus(ScProductConstant.RZSCORDER_STATUS02);// 变成办理中
        productOrderDao.updateByPrimaryKeySelective(productOrder);
        //节点更新记录表实体
        ProductNodeOperating operating = new ProductNodeOperating();
        operating.setId(operatingId);
        operating.setScProductOrderId(productOrder.getId());
        operating.setScProductOrderNo(productOrder.getScProductOrderNo());
        operating.setFlowUserId(userEntity.getId());
        operating.setFlowUserName(userEntity.getRealName());
        operating.setFlowOrgId(userEntity.getOrgId());
        operating.setFlowOrgName(map.get("name").toString());
        operating.setOrderStatus(productOrder.getStatus());
        operating.setNodeId(productNode.get(0).getId());
        operating.setNodeName(productNode.get(0).getName());
        operating.setRemarksType(1);
        //节点流程表实体
        ProductNodeFlow f = productNodeFlowDao.selectOneById(productOrder.getNodeFlowId());
        operating.setNodeProcessTimeType(f.getIsnaturalorworkday() == null ? null : f.getIsnaturalorworkday().toString());
        operating.setNodeOpetateTime(new Date());
        operating.setCreateUser(userEntity);
        operating.setCreateTime(new Date());
        operating.setCreaterOrgName(map.get("name").toString());
        //超期计算
        ProductTimeStatus timestatus = productTimeStatusDao.selectByPrimaryKey(productOrder.getId());
        if (timestatus == null) {
            timestatus = productTimeStatusService.insertProductStatus(productOrder);
        }
        if (null != timestatus && null != timestatus.getReceiveEndTime()) {
            int i = DateUtils.compare_date(new Date(), timestatus.getReceiveEndTime());
            if (i >= 1) {
                timestatus.setReceiveTimeStatus(ScProductConstant.TIME_OUT);
                operating.setNodeTimeStatus(ScProductConstant.TIME_OUT);
            } else {
                timestatus.setReceiveTimeStatus(timestatus.getReceiveTimeStatus());
                operating.setNodeTimeStatus(ScProductConstant.NORMAL);
            }
            operating.setNodeStartTime(timestatus.getReceiveStartTime());
            operating.setNodeEndTime(timestatus.getReceiveEndTime());

            productTimeStatusDao.updateTimeOutStatus(timestatus);
        }
        productNodeOperatingDao.insertProductNodeOperating(operating);
        // 插入操作记录
        /*SystemRecord record = new SystemRecord();
        record.setId(DggKeyWorker.nextId());// id
        record.setSource("2");
        record.setWorkTableName("rzsc_product_order");
        record.setWorkId(productOrder.getId());
        record.setWorkNo(productOrder.getScProductOrderNo());
        record.setOperateType("22");
        record.setRemarks("订单接单");
        systemRecordService.save(record);*/

    }

    /**
     * 暂缓恢复办理
     *
     * @param
     */
    @Transactional
    public void restoreOrderSuspended(String[] idsStrArray,String userLoginName) {
        UserEntity userEntity = searchUtils.getcurrUser(new HashMap(){{
            put("userLoginName", userLoginName);
        }});
        ValidateUtils.strNotEmpty(userEntity, ProductOrderExcption.class, "未获取到登陆人，请重新登录！");
        OrganizationEntity operatedOrgan = organizationManager.findOrgEntityByOrgId(userEntity.getOrgId());
        ValidateUtils.strNotEmpty(operatedOrgan, ProductOrderExcption.class, "未获取到登陆人部门信息，请重新登录！");
        ValidateUtils.strNotEmpty(idsStrArray, ProductOrderExcption.class, "生产订单ID不能为空！");
        //Assert.notNull(remark, "备注不能为空！");
        //Assert.isTrue(remark.length()<=500, "备注内容必须小于500个字!");
        /* 分割字符串*/
//        String[] idsStrArray = ids.split(",");
        Date now = new Date();
        List<SystemRecord> systemRecords = new ArrayList<>();
        for (int i = 0; i < idsStrArray.length; i++) {
            String id = idsStrArray[i];
            ProductOrder rzProductOrder = productOrderDao.selectByPrimaryKey(Long.parseLong(id));
            //判断登录人是否有权限操作这条记录
            ValidateUtils.strNotEmpty(rzProductOrder, ProductOrderExcption.class, "未查询到该生产订单的信息！");

//            Assert.isTrue(userEntity.getId().equals(rzProductOrder.getFlowUserId()), "只有流程人员才能进行该操作!");
            ValidateUtils.isTrue(userEntity.getId().equals(rzProductOrder.getFlowUserId()), ProductOrderExcption.class, "只有流程人员才能进行该操作!");
            //判断订单状态是否可进行操作
            String libStatus = rzProductOrder.getStatus();
            if (!ScProductConstant.RZSCORDER_STATUS03.equals(libStatus)) {//判断当前状态是否为暂缓状态
//                Assert.isTrue(false, "当前订单已更改，请刷新页面重试!");
                ValidateUtils.isTrue(false, ProductOrderExcption.class, "当前订单已更改，请刷新页面重试!");
            }
            /*if (null != rzProductOrder.getBeforeStatus() && !"".equals(rzProductOrder.getBeforeStatus())) {
                rzProductOrder.setStatus(rzProductOrder.getBeforeStatus()); //恢复到退单前的状态
            } else {*/
            rzProductOrder.setStatus(ScProductConstant.RZSCORDER_STATUS02); //办理中
            //}
            //rzProductOrder.setLastRemark(remark);
            //rzProductOrder.setLastRemarkTime(new Date());
            this.updateOpt(rzProductOrder, userEntity);
            productOrderDao.updateByPrimaryKeySelective(rzProductOrder);

            //恢复超期计算，重新计算超期
            ProductTimeStatus timeStatus = productTimeStatusDao.selectByPrimaryKey(rzProductOrder.getId());
            if (timeStatus == null) {
                timeStatus = productTimeStatusService.insertProductStatus(rzProductOrder);
            }
            if (timeStatus != null) {
                timeStatus.setStartSuspendTime(rzProductOrder.getSuspendTime());
                Date suspendStart = timeStatus.getStartSuspendTime();//暂缓开始时间
                Long suspendTime = now.getTime() - suspendStart.getTime();//暂缓实际自然时差

                timeStatus.setOrderSuspendMillisecond((timeStatus.getOrderSuspendMillisecond() == null ? 0L : timeStatus.getOrderSuspendMillisecond()) + suspendTime);
                timeStatus.setNodeSuspendMillisecond((timeStatus.getNodeSuspendMillisecond() == null ? 0L : timeStatus.getNodeSuspendMillisecond()) + suspendTime);
                Map map = new HashMap();
                ProductNodeFlow nodeFlow = null;
                Long serialId = commonService.getSerialId(rzProductOrder.getProductId());
                if(StringUtils.isNotEmpty(rzProductOrder.getNodeJson())){
                    Map maps = new HashMap<>();
                    maps.put("productId", serialId);
                    maps.put("businessTypeCode", rzProductOrder.getBusinessTypeCode());//一级业态Code
                    maps.put("smallBusinessTypeCode", rzProductOrder.getBusinessProductCode());// 二级业态Code
                    nodeFlow =  apiProductionService.getNodeFlow(maps);
                }else{
                    map.put("flowId", rzProductOrder.getNodeFlowId());
                    nodeFlow = productNodeFlowDao.queryFlowById(map);
                }
                int dateType = nodeFlow.getIsnaturalorworkday();
                Date newOrderEndTime = zzWorkDayService.getDateFromStartByType(timeStatus.getOrderStartTime(), timeStatus.getOrderProcessTime(), suspendTime, dateType);
                timeStatus.setOrderEndTime(newOrderEndTime);
            /*Date newNodeEndTime = zzWorkDayService.getDateFromStartByType(timeStatus.getNodeStartTime(), timeStatus.getNodeProcessTime(), suspendTime, dateType);
            timeStatus.setNodeEndTime(newNodeEndTime);

            timeStatus.setOrderEndTime(newOrderEndTime);*/

                timeStatus.setFlag(1);
                this.updateOpt(timeStatus, userEntity);
                productTimeStatusDao.updateByPrimaryKeySelective(timeStatus);
            }


            //-------操作记录------------
            SystemRecord systemRecord = new SystemRecord();
            //systemRecord.setId(DggKeyWorker.nextId());
            systemRecord.setWorkId(rzProductOrder.getId());
            systemRecord.setWorkNo(rzProductOrder.getScProductOrderNo());
            systemRecord.setWorkTableName("rzsc_product_order");
            systemRecord.setSource("2");//来源生产
            systemRecord.setRemarks("暂缓恢复办理");
            systemRecord.setOperateType("27");//操作类型 : 暂缓恢复办理
            systemRecord.setId(DggKeyWorker.nextId());
            systemRecord.setOperaterId(userEntity.getId());
            systemRecord.setOperaterName(userEntity.getRealName() + userEntity.getLoginName());
            systemRecord.setOperaterOrgId(operatedOrgan.getId());
            systemRecord.setOperaterOrgName(operatedOrgan.getName());
            systemRecord.setOperateTime(now);
            systemRecords.add(systemRecord);
            //systemRecordService.save(systemRecord);
            //-----------操作记录------------------
            //通过MQ推送消息到UC
            CustomerRecord customerRecord = new CustomerRecord();
            customerRecord.setCustomerId(rzProductOrder.getCustomerId());
            customerRecord.setTableName("rzsc_product_order");
            customerRecord.setTableId(rzProductOrder.getId());
            customerRecord.setTableNo(rzProductOrder.getScProductOrderNo());
            customerRecord.setRemarkType(ScNoteType.RZSC_NOTE_CODE13);
            customerRecord.setCreaterId(userEntity.getId());
            customerRecord.setContent("暂缓恢复办理");
            MQMessageSendUtil.ucMessageSend(customerRecord);
            //同步生产单状态给企大宝
            MQMessageSendUtil.qdsMessageSend(rzProductOrder,null,userEntity);
        }
        systemRecordService.saveRecords(systemRecords);

    }


    /**
     * 订单备注
     *
     * @param id
     * @param remark
     * @return
     */
    @SuppressWarnings("unchecked")
    @Transactional
    public void remarkOrder(Long id, String remark,String userLoginName) {
        ProductOrder order = productOrderDao.selectByPrimaryKey(id);
        UserEntity userEntity = searchUtils.getcurrUser(new HashMap(){{
            put("userLoginName", userLoginName);
        }});//当前操作人
        ValidateUtils.strNotEmpty(userEntity, ProductOrderExcption.class, "未获取到登陆人，请重新登录！");
        ValidateUtils.strNotEmpty(id, ProductOrderExcption.class, "生产订单ID不能为空");
        ValidateUtils.strNotEmpty(remark, ProductOrderExcption.class, "备注内容不能为空");
        ValidateUtils.strNotEmpty(order, ProductOrderExcption.class, "未查询到该生产订单的信息");

        ValidateUtils.isTrue(remark.length() <= 500, ProductOrderExcption.class, "备注内容必须小于500个字!");
        Map map = cmsService.findOrg(userEntity.getOrgId());
        ValidateUtils.strNotEmpty(map, ProductOrderExcption.class, "参数异常,备注失败！");
        ProductOrder productOrder1 = new ProductOrder();
        productOrder1.setId(id);
        productOrder1.setLastRemarkTime(new Date());
        productOrder1.setLastRemark(remark);
        productOrderDao.updateByPrimaryKeySelective(productOrder1);

        //插入操作记录
        SystemRecord record = new SystemRecord();
        record.setSource("2");
        record.setWorkTableName("rzsc_product_order");
        record.setWorkId(order.getId());
        record.setWorkNo(order.getScProductOrderNo());
        record.setOperateType("7");
        record.setRemarks("订单备注：" + remark);
        systemRecordService.apiSave(record,userEntity);
        //通过MQ推送消息到UC
        CustomerRecord customerRecord = new CustomerRecord();
        customerRecord.setCustomerId(order.getCustomerId());
        customerRecord.setTableName("rzsc_product_order");
        customerRecord.setTableId(order.getId());
        customerRecord.setTableNo(order.getScProductOrderNo());
        customerRecord.setRemarkType(ScNoteType.RZSC_NOTE_CODE1);
        customerRecord.setCreaterId(userEntity.getId());
        customerRecord.setContent(remark);
        MQMessageSendUtil.ucMessageSend(customerRecord);
        //同步生产单状态给企大宝
        MQMessageSendUtil.qdsMessageSend(order,null,userEntity);
    }

    /**
     * <p>@Description 移交保存</p>
     * <p>@author cuipeng</p>
     * <p>@Time 2019/1/14 创建时间</p>
     * <p>@return</p>
     */
    @Transactional
    public void saveTurnOver(Map map) {
        ValidateUtils.strNotEmpty(map.get("idStr"), ProductOrderExcption.class, "生产订单ID不能为空！");
        ValidateUtils.strNotEmpty(map.get("assistId"), ProductOrderExcption.class, "流程人员不能为空！");
        UserEntity userEntity = sessionManager.getCurrentUser();//当前操作人
        Long assistId = Long.valueOf(map.get("assistId").toString());
        UserEntity flower = userService.findUserById(assistId);
        Map flowOrg = cmsService.findOrg(flower.getOrgId());
        //ValidateUtils.strNotEmpty(flowOrg, ProductOrderExcption.class, "未获取到负责人部门,请重新选择负责人!");
        ValidateUtils.strNotEmpty(flowOrg, ProductOrderExcption.class, "未获取到负责人部门,请重新选择负责人！");
        String idStr = map.get("idStr").toString();
        String remark = map.get("remark") + "";
//        Assert.isTrue(remark.length()<=500, "备注内容最多不超过500个字!");
//        Assert.isTrue(remark.length()>=10, "备注内容不少于10个字!");
        ValidateUtils.strNotEmpty(map.get("remark"), ProductOrderExcption.class, "备注内容必须小于500个字!");
        ValidateUtils.isTrue(remark.length() <= 500, ProductOrderExcption.class, "备注内容必须小于500个字!");
        String[] split = idStr.split(",");
        //判断移交对象是不是当前登录人事业部下的人员
        //获取本部门及所有下属部门ID
        List<Long> childOrganizationList = commonMangerExtService.getChildOrganizationList(userEntity.getOrgId());
        Date now = new Date();
//        Assert.isTrue(childOrganizationList.contains(flower.getOrgId()),"移交人员不是当前登录人事业部下的人员！");
        ValidateUtils.isTrue(childOrganizationList.contains(flower.getOrgId()), ProductOrderExcption.class, "移交人员不是当前登录人事业部下的人员!");
        //操作记录
        SystemRecord systemRecord = new SystemRecord();
        for (String productId : split) {
            ProductOrder productOrder = productOrderDao.selectByPrimaryKey(Long.valueOf(productId));
            ValidateUtils.strNotEmpty(productOrder, ProductOrderExcption.class, "未查询到该生产订单的信息！生产订单ID：" + productId);
            //判断当前订单的流程人员是否离职
            Long flowUserIdOld = productOrder.getFlowUserId();
            if (StringUtils.isNotEmpty(flowUserIdOld)) {
                UserEntity oldUser = userService.findUserById(flowUserIdOld);
//                Assert.isTrue(oldUser.getLocked() == 2, "该生产订单流程人员未离职！生产订单ID："+productId);
                ValidateUtils.isTrue(oldUser.getLocked() == 2, ProductOrderExcption.class, "该生产订单流程人员未离职！生产订单ID：" + productId);
            }
//            Assert.isTrue(  !ScProductConstant.RZSCORDER_STATUS14.equals(productOrder.getStatus()) , "待分配订单不能移交!");
            ValidateUtils.isTrue(!ScProductConstant.RZSCORDER_STATUS14.equals(productOrder.getStatus()), ProductOrderExcption.class, "待分配订单不能移交");
            //移交前的人
            if (productOrder.getFlowUserId() != null) {//流程人员
                productOrder.setWaitingReceiverId(productOrder.getFlowUserId());
                productOrder.setWaitingReceiverName(productOrder.getFlowUserName());
                productOrder.setWaitingReceiverOrgId(productOrder.getFlowUserOrgId());
                productOrder.setWaitingReceiverOrgName(productOrder.getFlowUserOrgName());
            } else {//没有拿接收人
                productOrder.setWaitingReceiverId(productOrder.getReceiverId());
                productOrder.setWaitingReceiverName(productOrder.getReceiverName());
                productOrder.setWaitingReceiverOrgId(productOrder.getReceiverOrgId());
                productOrder.setWaitingReceiverOrgName(productOrder.getReceiverOrgName());
            }
            //接收人
            productOrder.setReceiverId(assistId);
            productOrder.setReceiverName(flower.getRealName() + flower.getLoginName());
            productOrder.setReceiverOrgId(flower.getOrgId());
            productOrder.setReceiverOrgName(flowOrg.get("name").toString());

            String status = productOrder.getStatus();
            //只有办理中和待接收的移交之后需要改变状态//////融资不需要改状态
            /*if (ScProductConstant.RZSCORDER_STATUS01.equals(status) || ScProductConstant.RZSCORDER_STATUS11.equals(status)
                    || ScProductConstant.RZSCORDER_STATUS15.equals(status) || ScProductConstant.RZSCORDER_STATUS16.equals(status)
                    || ScProductConstant.RZSCORDER_STATUS02.equals(status)) {
                productOrder.setStatus(ScProductConstant.RZSCORDER_STATUS15);
            }*/
            productOrder.setFlowUserId(assistId);
            productOrder.setFlowUserName(flower.getRealName() + flower.getLoginName());
            productOrder.setFlowUserOrgId(flower.getOrgId());
            productOrder.setFlowUserOrgName(flowOrg.get("name").toString());
            //修改退单 相关
            if (ScProductConstant.RZSCORDER_STATUS05.equals(status) || ScProductConstant.RZSCORDER_STATUS09.equals(status)
                    || ScProductConstant.RZSCORDER_STATUS06.equals(status)) {
                if (productOrder.getAbandonUserId() != null) {//修改退单申请人
                    productOrder.setAbandonUserId(assistId);
                    productOrder.setAbandonUser(flower.getRealName() + flower.getLoginName());
                }
            }
            productOrder.setOriginCode(ScProductConstant.RZSC_ORIGINCODE_MOVE);//修改来源方式
            if (StringUtils.isNotEmpty(remark)) {
                productOrder.setRemark(remark.toString());
                //最新备注时间
                productOrder.setLastRemarkTime(new Date());
                productOrder.setLastRemark(remark);
            }
            this.updateOpt(productOrder, sessionManager.getCurrentUser());
            productOrderDao.updateByPrimaryKeySelective(productOrder);

            //超期计算

            ProductTimeStatus timestatus = productTimeStatusDao.selectByPrimaryKey(productOrder.getId());
            if(timestatus==null){
                timestatus = productTimeStatusService.insertProductStatus(productOrder);
            }else {
                timestatus.setReceiveStartTime(now);
                timestatus.setReceiveProcessTime(1);
                try {
                    timestatus.setReceiveEndTime(DateUtils.dateAddDayJs(now, 1));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                productTimeStatusDao.updateByPrimaryKey(timestatus);
            }
            systemRecord.setBeOperaterId(assistId);
            systemRecord.setBeOperaterName(flower.getRealName() + flower.getLoginName());
            systemRecord.setBeOperaterOrgId(flower.getOrgId());
            systemRecord.setBeOperaterOrgName(flowOrg.get("name") + "");
            systemRecord.setWorkId(productOrder.getId());
            systemRecord.setWorkNo(productOrder.getScProductOrderNo());
            systemRecord.setWorkTableName("rzsc_product_order");
            systemRecord.setSource("2");//来源生产
            systemRecord.setOperateType("13");//操作类型 : 移交
            systemRecord.setRemarks("移交生产订单");
            systemRecordService.save(systemRecord, flower,userEntity);//保存上被操作人
            //调用发送消息公共方法
            // 生产订单{0}已经于{1}移交给你，请及时确认处理！
            try {//不让影响其他功能,发送失败就算了
                String[] msgs = new String[]{productOrder.getScProductOrderNo(), DateUtil.dateToString(now, "yyyy-MM-dd HH:mm:ss")};
                List<UserEntity> users = new ArrayList<>();
                users.add(flower);//接收人
                commonService.sendMsgByAsynchronous(users, msgs, "RZSC_SC_TURN_OVER");//移交模板
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }


    /**
     * <p>@Description 事业部移交保存</p>
     * <p>@author mqy</p>
     * <p>@Time 2019/1/11 创建时间</p>
     * <p>@return</p>
     */
    @Transactional
    @SuppressWarnings("all")
    public void saveTurnOverOrg(String orderId, String productId) {

        ValidateUtils.strNotEmpty(orderId, ProductOrderExcption.class, "订单ID不能为空！");
        ValidateUtils.strNotEmpty(productId, ProductOrderExcption.class, "移交事业部ID不能为空！");
        UserEntity userentity = sessionManager.getCurrentUser();
        ValidateUtils.strNotEmpty(userentity, ProductOrderExcption.class, "未获取到登陆人，请重新登录！");
        Map orgMap = commonMangerExtService.findBusDeptById(userentity.getOrgId());

        ValidateUtils.strNotEmpty(orgMap, ProductOrderExcption.class, "登录用户所属事业部信息为空！");
//        Assert.isTrue(!orgMap.get("id").toString().equals(productId),"同事业部不能移交！");
        ValidateUtils.isTrue(!orgMap.get("id").toString().equals(productId), ProductOrderExcption.class, "同事业部不能移交");
        List<ProductOrder> list = productOrderDao.getListByOrderId(Long.parseLong(orderId), null, null);
        Map mapUser = commonMangerExtService.findOrg(userentity.getOrgId());
        Date date = new Date();
        for (int i = 0; i < list.size(); i++) {
            //修改生产订单
            ProductOrder po = list.get(i);
            Map productOrg = commonMangerExtService.findBusDeptById(Long.parseLong(productId));

            ValidateUtils.strNotEmpty(productOrg, ProductOrderExcption.class, "待移交的事业部查询为空！");
            po.setStatus(ScProductConstant.RZSCORDER_STATUS14);//事业部移交 统一更改状态为待分配
            po.setProductOrgId(Long.parseLong(productId));
            po.setProductOrgName(productOrg.get("name") + "");
            po.setTransferTime(date);
            po.setTransferUserId(userentity.getId());
            po.setTransferUserName(userentity.getRealName() + "(" + userentity.getLoginName() + ")");
            po.setTransferUserOrgId(Long.parseLong(orgMap.get("id").toString()));
            po.setUpdaterId(userentity.getId());
            po.setUpdaterName(userentity.getRealName());
            po.setUpdaterOrgId(userentity.getOrgId());
            po.setUpdaterOrgName(mapUser.get("name").toString());
            po.setUpdateTime(date);

            po.setLatestEndNodeName("");
            po.setLatestEndNodeId(null);
            po.setLatestEndNodeTime(null);
            po.setFlowUserId(null);
            po.setFlowUserName("");
            po.setFlowUserOrgId(null);
            po.setFlowUserOrgName("");
            po.setReceiverId(null);
            //po.setProductUserId(null);
            //po.setProductUserOrgId(null);
            po.setCompletedTime(null);

            //修改流程id
            Map maps = new HashMap<>();
//            maps.put("businessCode", po.getBusinessProductCode());
            Long serialId = commonService.getSerialId(po.getProductId());
//            maps.put("productId", serialId);
//            ProductNodeFlow node = productNodeFlowDao.queryFlowAndNodeVersionByBusinessAndProductId(maps);
            maps.put("productId", serialId);
            maps.put("businessTypeCode", po.getBusinessTypeCode());//一级业态Code
            maps.put("smallBusinessTypeCode", po.getBusinessProductCode());// 二级业态Code
            ProductNodeFlow nodeFlow =  apiProductionService.getNodeFlow(maps);
            ValidateUtils.isTrue(StringUtils.isNotEmpty(nodeFlow), CommonExcption.class, "未查询到" + po.getBusinessProductName()+"-"+po.getProductName() + "流程节点配置信息");
            po.setNodeFlowId(nodeFlow.getId());
            po.setVersion(nodeFlow.getVersion());
            List<ProductNode> nodeList = apiProductionService.getProductNode(nodeFlow);
            String nodeStr = JSONObject.toJSONString(nodeList);
            po.setNodeJson(nodeStr);//设置节点数据
            //添加来源方式
            po.setOriginCode(ScProductConstant.RZSC_ORIGINCODE_DEPT);
            productOrderDao.updateByPrimaryKeySelective(po);

            //移除协单人员
            Map map = new HashMap();
            map.put("scProductOrderId", po.getId());
            List<Assistant> assistants = assistantDao.query(map);
            for (int k = 0; k < assistants.size(); k++) {
                assistantDao.deleteByPrimaryKey(assistants.get(k).getId());
            }


            //修改生产订单超期
            ProductTimeStatus timestatus = productTimeStatusDao.selectByPrimaryKey(po.getId());//需要确定下如果为空是不是需要新增
            if (timestatus == null) {
                timestatus = productTimeStatusService.insertProductStatus(po);
            }
            if (timestatus != null) {
                try {
                    timestatus.setDistributionEndTime(DateUtils.dateAddDayJs(new Date(), 1));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                if (nodeFlow.getIsnaturalorworkday() == 1) {//工作日
                    Date nowDate = new Date();
                    String orderEndTime = cmsservice.findAfterDate(DateUtil.dateToString(nowDate, "yyyy-MM-dd HH:mm:ss"), nodeFlow.getManagementCycle()) + " " + DateUtil.dateToString(nowDate, "HH:mm:ss");
                    timestatus.setOrderEndTime(DateUtil.stringToDate(orderEndTime, "yyyy-MM-dd HH:mm:ss"));
                } else {
                    try {
                        timestatus.setOrderEndTime(DateUtils.dateAddDayJs(new Date(), nodeFlow.getManagementCycle()));
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                }
                productTimeStatusDao.updateByPrimaryKey(timestatus);
            }

            //插入记录
            SystemRecord record = new SystemRecord();
            record.setSource("2");
            record.setWorkTableName("rzsc_product_order");
            record.setWorkId(po.getId());
            record.setWorkNo(po.getScProductOrderNo());
            record.setOperateType("38");
            record.setRemarks("事业部移交");
            OrganizationEntity operatedOrgan = organizationManager.findOrgEntityByOrgId(userentity.getOrgId());
            record.setOperaterOrgName(operatedOrgan.getName());
            systemRecordService.save(record, userentity,userentity);//保存上被操作人
        }
    }

    /**
     * <p>@Description 通过客户ID查电话</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/13 0013 14:44 创建时间</p>
     * <p>@return</p>
     */
    public String findPhoneByCustomerId(Long customerId) {
        CustomerDTO customerDTO = ucApiService.findCustomerById(customerId);
        if (customerDTO != null) {
            String[] dtoColumn = {"sex", "origin", "businessArea", "customerType"};
            customerDTO = translateUtil.translateObject(dtoColumn, customerDTO);
            String number = this.desUtil.decrypt(customerDTO.getNumber());//解密电话号码
            customerDTO.setNumber(number);
            return customerDTO.getNumber();
        }
        return "";
    }

    /**
     * 订单导出查询列表
     */
    public List<ProductOrderDto> queryOrderList(Map params) {
        List<String> statusAttr = new ArrayList<>();
        if(StringUtils.isNotEmpty(params.get("statusAttrs"))){
            params.put("statusArr", params.get("statusAttrs"));
        }else {
            if (StringUtils.isNotEmpty(params.get("statusAttr"))) {
                statusAttr.add(params.get("statusAttr") + "");
            }
            params.put("statusArr", statusAttr);
        }
        //入参操作
        searchUtils.paramsOperate(params);
        List<ProductOrderDto> list = productOrderDao.scOrderWithPage(params);
        //翻译字段
        String[] transColum = {"originCode", "status", "suspendReason"};
        list = translateUtil.translateList(transColum, list);
        //隐藏字段
        String[] hideColum = {"customerPhone"};
        list = desUtil.decryptList(hideColum, list);
        list = CustomerNumberEncryptionUtil.encryptionList(hideColum, list);
        return list;
    }

    /**
     * 订单导出查询列表
     */
    public List<UploadWjOrderDto> queryOrderListDsh(Map params) {
        if(StringUtils.isNotEmpty(String.valueOf(params.get("completedTime")))){
            String abandonReasonTime=String.valueOf(params.get("completedTime"));
            String abandonReasonTimeStart=abandonReasonTime.substring(0,abandonReasonTime.indexOf("~"));
            abandonReasonTimeStart= abandonReasonTimeStart.trim();
            String abandonReasonTimeEnd = abandonReasonTime.substring(abandonReasonTime.indexOf("~") + 1);
            abandonReasonTimeEnd= abandonReasonTimeEnd.trim();
            params.put("completedTimeStart", abandonReasonTimeStart);
            params.put("completedTimeEnd", abandonReasonTimeEnd);
        }
        List<UploadWjOrderDto> list = productOrderDao.queryOrderWjsh(params);
        return list;
    }


    /**
     * <p>@Description 数据统计</p>
     * <p>@author zyou</p>
     */
    public Map scOrderCountData(Map param) {
        UserEntity userentity = sessionManager.getCurrentUser();
        Map resultMap = new HashMap();
        if ("1".equals(param.get("isAll"))) {
            //有查看全部的权限并且没有传事业部条件进来才查总的
            if (StringUtils.isEmpty(param.get("signOrgId"))) {
                Map map = productOrderDao.selectScOrderCountTotal(param);
                resultMap.put("orderTotal", map);
            }
        } else {
            //没有看全部的权限就查自己所在事业部的
            Long userSybId = commonService.findUserSyb(userentity);//查事业部ID
            param.put("signOrgId", userSybId);
        }
        List<Map> maps = productOrderDao.selectScOrderCount(param);
        resultMap.put("orderCount", maps);
        return resultMap;
    }

    /**
     * 统计概况导出
     *
     * @param params
     * @return
     */
    public List<OrderCountDto> exportOrderCountData(Map params) {
        List<Map> maps = productOrderDao.selectScOrderCount(params);
        List<OrderCountDto> orderCountVoList = new ArrayList<>();
        if (maps != null && !maps.isEmpty()) {
            for (Map map : maps) {
                OrderCountDto orderCountVo = new OrderCountDto();
                orderCountVo.setProductOrgName(map.get("productOrgName") == null ? "" : map.get("productOrgName").toString());
                orderCountVo.setWaitAllotCount(map.get("waitAllotCount") == null ? "0" : map.get("waitAllotCount").toString());
                orderCountVo.setWaitReceiveCount(map.get("waitReceiveCount") == null ? "0" : map.get("waitReceiveCount").toString());
                orderCountVo.setInprocessCount(map.get("inprocessCount") == null ? "0" : map.get("inprocessCount").toString());
                orderCountVo.setSuspendCount(map.get("suspendCount") == null ? "0" : map.get("suspendCount").toString());
                orderCountVo.setTddshCount(map.get("tddshCount") == null ? "0" : map.get("tddshCount").toString());
                orderCountVo.setFddshCount(map.get("fddshCount") == null ? "0" : map.get("fddshCount").toString());
                orderCountVo.setTdbhCount(map.get("tdbhCount") == null ? "0" : map.get("tdbhCount").toString());
                orderCountVo.setFdbhCount(map.get("fdbhCount") == null ? "0" : map.get("fdbhCount").toString());
                orderCountVo.setYtdCount(map.get("ytdCount") == null ? "0" : map.get("ytdCount").toString());
                orderCountVo.setYfdCount(map.get("yfdCount") == null ? "0" : map.get("yfdCount").toString());
                orderCountVo.setScwjCount(map.get("scwjCount") == null ? "0" : map.get("scwjCount").toString());
                orderCountVo.setTotal(map.get("total") == null ? "0" : map.get("total").toString());
                orderCountVoList.add(orderCountVo);
            }
        }
        //传了事业部进来就不用查总的了
        if ("1".equals(params.get("isAll")) || StringUtils.isEmpty(params.get("signOrgId"))) {
            Map map = productOrderDao.selectScOrderCountTotal(params);
            OrderCountDto orderCountVo = new OrderCountDto();
            orderCountVo.setProductOrgName("总计");
            orderCountVo.setWaitAllotCount(map.get("waitAllotTotal") == null ? "0" : map.get("waitAllotTotal").toString());
            orderCountVo.setWaitReceiveCount(map.get("waitReceiveTotal") == null ? "0" : map.get("waitReceiveTotal").toString());
            orderCountVo.setInprocessCount(map.get("inprocessTotal") == null ? "0" : map.get("inprocessTotal").toString());
            orderCountVo.setSuspendCount(map.get("suspendTotal") == null ? "0" : map.get("suspendTotal").toString());
            orderCountVo.setTddshCount(map.get("tddshTotal") == null ? "0" : map.get("tddshTotal").toString());
            orderCountVo.setFddshCount(map.get("fddshTotal") == null ? "0" : map.get("fddshTotal").toString());
            orderCountVo.setTdbhCount(map.get("tdbhTotal") == null ? "0" : map.get("tdbhTotal").toString());
            orderCountVo.setFdbhCount(map.get("fdbhTotal") == null ? "0" : map.get("fdbhTotal").toString());
            orderCountVo.setYtdCount(map.get("ytdTotal") == null ? "0" : map.get("ytdTotal").toString());
            orderCountVo.setYfdCount(map.get("yfdTotal") == null ? "0" : map.get("yfdTotal").toString());
            orderCountVo.setScwjCount(map.get("scwjTotal") == null ? "0" : map.get("scwjTotal").toString());
            orderCountVo.setTotal(map.get("allTotal") == null ? "0" : map.get("allTotal").toString());
            orderCountVoList.add(orderCountVo);
        }
        return orderCountVoList;
    }

    /**
     * 统计融资生产首页信息数量
     *
     */
    public Map<String, Object> statisticFinancingDataCount(String userLoginName) {
        Map<String, Object> params = new HashMap<>();
        params.put("userLoginName",userLoginName);
        UserEntity  userEntity = searchUtils.getcurrUser(params);
        ValidateUtils.strNotEmpty(userEntity, ProductOrderExcption.class, "未获取到登陆人，请重新登录！");
        dataPermissionUtils.flowUserDataAccess(params, ModuleCodeConstant.RZSC_APP_WORKBENCH);
        Map<String, Object> map=productOrderDao.statisticFinancingDataCount(params);
        Map<String, Object> paramsAudit = new HashMap<>();
        paramsAudit.put("userLoginName",userLoginName);
        //待审核数据
        dataPermissionUtils.auditorDataAccess(paramsAudit);
        map.put("examine", productOrderDao.statisticExamine(paramsAudit));
        Map<String, Object> paramsHandle = new HashMap<>();
        paramsHandle.put("userLoginName",userLoginName);
        //处理中
        dataPermissionUtils.inProcessDataAccess(paramsHandle, ModuleCodeConstant.RZSC_PROCESSING_CODE);
        map.put("handle", productOrderDao.statisticHandle(paramsHandle));
        return  map;
    }
}
